package map;

import java.util.*;

//遍历
public class MapDemo2 {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("语文",99);
        map.put("数学",98);
        map.put("英语",97);
        map.put("物理",96);
        map.put("化学",99);
        System.out.println(map);

        Set<String> strings = map.keySet();
        for (String string : strings) {
            System.out.println(string);
        }

        Collection<Integer> values = map.values();
        for (Integer value : values) {
            System.out.println(value);
        }

        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            String key = entry.getKey();
            System.out.println(key);
            Integer value = entry.getValue();
            System.out.println(value);
        }

        Collection<String> c = new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");

        for (String s : c) {
            System.out.println(s);
        }

        c.forEach(s-> System.out.println(s));

        map.forEach((k,v)-> System.out.println(k+":"+v));



    }
}
